<?php
/*
	插件概览
*/
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
if($_RQ['op']=='edit'){
	$return['typetitle']='盒标装箱';
	$item=array(
		'type'=>0,
		'codes'=>array(),
		'merchid'=>'0',
		'storeid'=>$this->store_id,
		'workerid'=>$this->workerid,
	);
	$return['item']=$item;
	$return['worker']=$worker;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$xcode=$_RQ['xcode'];
	if(!$xcode){
		exi('请扫箱标签！','error');
	}
	if(!$postdata['codes']){
		exi('请扫标签！','error');
	}
	if(count($postdata['codes'])!=48){
		exi('请扫入48个盒标！','error');
	}
	$this->model('store')->uphelog2($postdata,$xcode);
	exi('操作成功！','','/store.index/');
}
if($_RQ['op']=='check_xcode'){
	$nowxcode=trim($_RQ['nowxcode']);
	$xcode=pdo_get('jy_yxgoodserpfw_xcode',array('code'=>$nowxcode,'uniacid'=>$_SESSION['uniacid']));
	if(!$xcode['id']){
		$msg='箱标签不存在！';
	}
	if($xcode['log_status']){
		$msg='箱码'.$nowxcode.'不属于【未入库】状态，不能操作！';
	}
	$res['success']=$msg?0:1;
	$res['msg']=$msg;
	exi($res);
}
if($_RQ['op']=='check_status'){
	$post=get_postdata();
	if(!$_RQ['nowcode']){
		$res['isnonowcode']=1;
		exi($res);
	}
	$ismerch=intval($_RQ['ismerch']);
	$nowcode=trim($_RQ['nowcode']);
	$nowxcode=trim($_RQ['nowxcode']);
	$type=$post['type'];
	$code_type=1;
	if($post['type']==6){
		$type=0;
		$code_type=0;
	}elseif($post['type']==10){
		$type=1;
		$code_type=0;
	}elseif($post['type']==30){
		$type=3;
		$code_type=0;
	}
	if($_RQ['iszhuang']){
		$code_type=0;
	}
	$log=array(
		'type'=>$type,
		'code'=>$nowcode,
		'code_type'=>$code_type,
	);
	//print_r($log);exit;
	if($nowxcode){
		$xcode=pdo_get('jy_yxgoodserpfw_xcode',array('code'=>$nowxcode,'uniacid'=>$_SESSION['uniacid']));
	}
	$log['code_item']=pdo_get('jy_yxgoodserpfw_code',array('code'=>trim($nowcode),'uniacid'=>$_SESSION['uniacid']));
	$msg=$this->model('model')->check_status($log,$ismerch,true,$xcode);
	if(!$msg && $nowxcode){
		$type=4;
		$code_type=0;
		$cv['code']=trim($log['code']);
		$item=$log['code_item'];
		$code_num=1;
		$batch[$item['batch_id']]=$batch[$item['batch_id']]?:pdo_getcolumn('jy_yxgoodserpfw_batch',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['batch_id']),'pre');
		$item['pre']=$batch[$item['batch_id']];
		if(!$item['id']){
			exi($cv['code'].'标签不属于盒标签!!','error');
		}
		//$isadd=pdo_get('jy_yxgoodserpfw_kulog',array('type'=>0,'code'=>$cv['code'],'uniacid'=>$_SESSION['uniacid']));
		if($isadd['id']){
			//exi($cv['code'].'标签重复操作！','error');
		}
		$goods_id=$item['goods_id'];
		$batch_id=$item['batch_id'];
		$item['sn']=sprintf("%08d", $item['sn']);
		$item['presn']=$item['pre'].$item['sn'];
		$sn=$item['presn'];
		$xiang_id=$xcode['id'];
		$log=array(
				'type'=>0,
				'code'=>$cv['code'],
				'storeid'=>$post['storeid'],
				'workerid'=>$post['workerid'],
				'goods_id'=>$goods_id,
				'batch_id'=>$batch_id,
				'xiang_id'=>$xiang_id,
				'sn'=>$sn,
				'code_type'=>$code_type,
				'xiang_num'=>1,
				'code_num'=>$code_num,
				'remark'=>$post['remark'],
		);
		$log['uniacid']=$_SESSION['uniacid'];
		$log['createtime']=TIMESTAMP;
		//$this->model('model')->upcodelog_status($log);
		pdo_insert('jy_yxgoodserpfw_kulog',$log);
		pdo_update('jy_yxgoodserpfw_code',array('xcode2'=>$nowxcode,'log_status'=>1,'xiang_id'=>$xiang_id),array('log_status'=>0,'code'=>$cv['code'],'uniacid'=>$_SESSION['uniacid']));
	}
	$res['success']=$msg?0:1;
	$res['msg']=$msg;
	exi($res);
}